import 'package:flutter/material.dart';
import 'package:flutter_fresh_mall_app/page/cart/shoppingCart.dart';
import 'package:flutter_fresh_mall_app/page/home/home.dart';
import 'package:flutter_fresh_mall_app/page/myinfo/myInfo.dart';

import 'category/category.dart';
//初始页
class IndexPage extends StatefulWidget {
  @override
  State createState() => IndexState();
}

class IndexState extends State<IndexPage> {
  //底部导航栏
  final List<BottomNavigationBarItem> navigationList = [
    BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
    BottomNavigationBarItem(icon: Icon(Icons.search), label: '分类'),
    BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), label: '购物车'),
    BottomNavigationBarItem(icon: Icon(Icons.perm_identity_rounded), label: '我的')
  ];
  int currentIndex;
  PageController _pageController = PageController();

  @override
  void initState() {
    currentIndex = 0;
    super.initState();
  }

  void switchPage(int index) {
    setState(() {
      this.currentIndex = index;
      _pageController.jumpToPage(index);
    });
  }

  @override
  Widget build(BuildContext context) {
   return new Scaffold(

      bottomNavigationBar: BottomNavigationBar(
        items: navigationList,
        type: BottomNavigationBarType.fixed,
        currentIndex: this.currentIndex,
        onTap: (index) async => switchPage(index),
      ),
      body: PageView(
        controller: _pageController,
        children: [
          HomePage(),
          CategoryPage(),
          ShoppingCartPage(),
          MyInfoPage(),//我的
        ],
      ),
    );
  }
}
